package com.gp.cyg.utils;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.*;

/**
 * ThreadPoolUtls
 *
 * @author gsp
 * @date 2022/9/19
 */
@Component
public class ThreadPoolUtils {
    public ThreadPoolExecutor threadPoolExecutor;
    public ThreadPoolExecutor backThreadPoolExecutor;


    @PostConstruct
    public void initThreadPoolExecutor() {
        threadPoolExecutor = new ThreadPoolExecutor(2*Runtime.getRuntime().availableProcessors(), 2*Runtime.getRuntime().availableProcessors(), 1000,
                TimeUnit.SECONDS, new SynchronousQueue<>(),  new ThreadPoolExecutor.DiscardPolicy());
        backThreadPoolExecutor = new ThreadPoolExecutor(1, 1, 1000,
                TimeUnit.SECONDS, new SynchronousQueue<>(),  new ThreadPoolExecutor.DiscardPolicy());
    }


    public ThreadPoolExecutor getThreadPoolExecutor() {
        return threadPoolExecutor;
    }

    public ThreadPoolExecutor getBackThreadPoolExecutor() {
        return backThreadPoolExecutor;
    }

}
